package com.cyclecoder.thread;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author by zhanglei
 * @Date 2021/8/9
 */
public class ThreadCallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                Thread.sleep(1000);
                return new Random().nextInt(100);
            }
        };
        FutureTask ft = new FutureTask(callable);
        new Thread(ft, "callable线程").start();

        System.out.println("hello callable");
        System.out.println(ft.isDone());
        System.out.println("tf is done");
        System.out.println(ft.get());
        System.out.println(">>>>");

    }
}
